package com.gzq.controller;

import com.gzq.entity.Article;
import com.gzq.service.ArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: duzi55
 * @date: 2019-06-03 16:16
 */
@RestController
public class ArticleController {
    @Resource
    ArticleService articleService;
    @GetMapping("findall")
    public Map findAll(@RequestParam("page") Integer page){
        Map map =new HashMap();
        map.put("news", articleService.findAll(page));
        return map;
    }
    @PostMapping("savanew")
    public boolean savaNew( Article article){
        return articleService.savaNew(article);
    }
    @GetMapping("findbyid")
    public Article findById(long id){
        return  articleService.findById(id);
    }
    @RequestMapping("delete")
    public boolean deleteById(long id){
        return articleService.deletById(id);
    }
    @RequestMapping("update")
    public boolean update(Article article){

        return articleService.savaNew(article);
    }
    @RequestMapping("search")
    public List<Article> search(@RequestParam("key") String key){
        return articleService.findBytitleLike(key);
    }
}
